/*创建options对象*/
import { reqDictsDataByType } from '@/api/system/dict/data.ts'
import dictConverter from '@/utils/dict/DictConverter.ts'
import { mergeRecursive } from '@/utils/yixia.ts'

export const options = {
  metas: {
    '*': {
      request: (dictMeta: any) => {
        return Promise.resolve([])
      },
      responseConverter,
      labelField: 'label',
      valueField: 'dictValue',
    },
  },

  DEFAULT_LABEL_FIELDS: ['label', 'name', 'title'],
  DEFAULT_VALUE_FIELDS: ['value', 'id', 'uid', 'key'],
}

/*对response响应数据进行处理*/
function responseConverter(response: any, dictMeta: any) {
  const dicts = response
  /*返回值不能为空*/
  if (dicts === undefined || dicts === null) {
    console.warn(`no dict data of "${dictMeta.type}" found in the response `)
    return []
  }
  return dicts.map((d: any) => {
    return dictConverter(d, dictMeta)
  })
}

/*合并options*/
export function mergeOptions(src) {
  mergeRecursive(options, src)
  console.log('sqp options', options)
}

export default options
